﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WechatDAL
{
    public static partial class WechatAPI4Ent
    {
        internal static string Token { get { return "6vz0t7E7RP40E350jCzJtZsDNW"; } }
        internal static string AESKey { get { return "g8m6gskFMjLw5MXPW6b4BaZiVOkHTcHjHnVxClPYBK5"; } }
        internal static string CorpID { get { return "wx05593f9d1d4e3594"; } }
        internal static string CorpSecret { get { return "vEnzrvOEKtqRXkyxepSOb_45RmSmX9WbRLPlhaqBCaqk5nKgOKxiyJ78__1n-u4e"; } }

        private static string _oAuth = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri={0}&response_type=code&scope={1}{2}#wechat_redirect";
        /// <summary>
        /// 获取网页授权页面
        /// </summary>
        public static string OAuth
        {
            get { return _oAuth.Replace("=APPID", "=" + CorpID); }
        }

        private static string _getJSTicket = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=ACCESS_TOKEN";
        /// <summary>
        /// 获取JS接口ticket
        /// </summary>
        public static string GetJSTicket
        {
            get { return _getJSTicket.SetToken(); }
        }

        #region 部门
        private static string _addDepartment = "https://qyapi.weixin.qq.com/cgi-bin/department/create?access_token=ACCESS_TOKEN";
        /// <summary>
        /// 创建部门
        /// </summary>
        public static string AddDepartment
        {
            get { return WechatAPI4Ent._addDepartment.SetToken(); }
        }

        private static string _updateDepartment = "https://qyapi.weixin.qq.com/cgi-bin/department/update?access_token=ACCESS_TOKEN";
        /// <summary>
        /// 修改部门
        /// </summary>
        public static string UpdateDepartment
        {
            get { return WechatAPI4Ent._updateDepartment.SetToken(); }
        }

        private static string _deleteDepartment = "https://qyapi.weixin.qq.com/cgi-bin/department/delete?access_token=ACCESS_TOKEN&id=";
        /// <summary>
        /// 删除部门
        /// </summary>
        public static string DeleteDepartment
        {
            get { return WechatAPI4Ent._deleteDepartment.SetToken(); }
        }

        private static string _getDepartmentList = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=ACCESS_TOKEN&id=ID";
        /// <summary>
        /// 获取部门列表
        /// </summary>
        public static string GetDepartmentList
        {
            get { return WechatAPI4Ent._getDepartmentList.SetToken(); }
        }
        #endregion

        #region 标签/角色
        private static string _addTag = "https://qyapi.weixin.qq.com/cgi-bin/tag/create?access_token=ACCESS_TOKEN";
        /// <summary>
        /// 创建标签
        /// </summary>
        public static string AddTag
        {
            get { return WechatAPI4Ent._addTag.SetToken(); }
        }

        private static string _updateTag = "https://qyapi.weixin.qq.com/cgi-bin/tag/update?access_token=ACCESS_TOKEN";
        /// <summary>
        /// 更新标签
        /// </summary>
        public static string UpdateTag
        {
            get { return WechatAPI4Ent._updateTag.SetToken(); }
        }

        private static string _deleteTag = "https://qyapi.weixin.qq.com/cgi-bin/tag/delete?access_token=ACCESS_TOKEN&tagid=1";
        /// <summary>
        /// 删除标签
        /// </summary>
        public static string DeleteTag
        {
            get { return WechatAPI4Ent._deleteTag.SetToken(); }
        }

        private static string _getTagUsers = "https://qyapi.weixin.qq.com/cgi-bin/tag/get?access_token=ACCESS_TOKEN&tagid=1";
        /// <summary>
        /// 获取标签成员
        /// </summary>
        public static string GetTagUsers
        {
            get { return WechatAPI4Ent._getTagUsers.SetToken(); }
        }

        private static string _addTagUser = "https://qyapi.weixin.qq.com/cgi-bin/tag/addtagusers?access_token=ACCESS_TOKEN";
        /// <summary>
        /// 添加标签成员
        /// </summary>
        public static string AddTagUser
        {
            get { return WechatAPI4Ent._addTagUser.SetToken(); }
        }

        private static string _deleteTagUser = "https://qyapi.weixin.qq.com/cgi-bin/tag/deltagusers?access_token=ACCESS_TOKEN";
        /// <summary>
        /// 删除标签成员
        /// </summary>
        public static string DeleteTagUser
        {
            get { return WechatAPI4Ent._deleteTagUser.SetToken(); }
        }

        private static string _getTagList = "https://qyapi.weixin.qq.com/cgi-bin/tag/list?access_token=ACCESS_TOKEN";
        /// <summary>
        /// 获取标签列表
        /// </summary>
        public static string GetTagList
        {
            get { return WechatAPI4Ent._getTagList.SetToken(); }
        }

        #endregion

        #region 成员
        private static string _addUser = "https://qyapi.weixin.qq.com/cgi-bin/user/create?access_token=ACCESS_TOKEN";
        /// <summary>
        /// 创建成员
        /// </summary>
        public static string AddUser
        {
            get { return WechatAPI4Ent._addUser.SetToken(); }
        }

        private static string _updateUser = "https://qyapi.weixin.qq.com/cgi-bin/user/update?access_token=ACCESS_TOKEN";
        /// <summary>
        /// 修改成员
        /// </summary>
        public static string UpdateUser
        {
            get { return WechatAPI4Ent._updateUser.SetToken(); }
        }

        private static string _deleteUser = "https://qyapi.weixin.qq.com/cgi-bin/user/delete?access_token=ACCESS_TOKEN&userid=";
        /// <summary>
        /// 删除成员
        /// </summary>
        public static string DeleteUser
        {
            get { return WechatAPI4Ent._deleteUser.SetToken(); }
        }

        private static string _deleteUsers = "https://qyapi.weixin.qq.com/cgi-bin/user/batchdelete?access_token=ACCESS_TOKEN";
        /// <summary>
        /// 删除多个成员
        /// </summary>
        public static string DeleteUsers
        {
            get { return WechatAPI4Ent._deleteUsers.SetToken(); }
        }

        private static string _getUserInfo = "https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&userid=lisi";
        /// <summary>
        /// 获取成员信息
        /// </summary>
        public static string GetUserInfo
        {
            get { return WechatAPI4Ent._getUserInfo.SetToken(); }
        }

        private static string _getUserListByDepartment = "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token=ACCESS_TOKEN&department_id=1&fetch_child=0&status=0";
        /// <summary>
        /// 根据部门获取成员列表（简单信息）
        /// </summary>
        public static string GetUserListByDepartment
        {
            get { return WechatAPI4Ent._getUserListByDepartment.SetToken(); }
        }

        private static string _getUserInfosByDepartment = "https://qyapi.weixin.qq.com/cgi-bin/user/list?access_token=ACCESS_TOKEN"; //&department_id=&fetch_child=&status=
        /// <summary>
        /// 根据部门获取成员信息（复杂信息）
        /// </summary>
        public static string GetUserInfosByDepartment
        {
            get { return WechatAPI4Ent._getUserInfosByDepartment.SetToken(); }
        }

        private static string _inviteUser = "https://qyapi.weixin.qq.com/cgi-bin/invite/send?access_token=ACCESS_TOKEN";
        /// <summary>
        /// 向成员发送关注企业号的邀请
        /// </summary>
        public static string InviteUser
        {
            get { return WechatAPI4Ent._inviteUser.SetToken(); }
        }

        private static string _oAuthUserinfo = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token=ACCESS_TOKEN&code={0}&agentid={1}";
        /// <summary>
        /// 根据CODE获取成员信息
        /// </summary>
        public static string OAuthUserinfo
        {
            get { return WechatAPI4Ent._oAuthUserinfo.SetToken(); }
        }

        #endregion

        #region 消息
        private static string _sendMessage = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=ACCESS_TOKEN";
        /// <summary>
        /// 发送消息
        /// </summary>
        public static string SendMessage
        {
            get { return WechatAPI4Ent._sendMessage.SetToken(); }
        }
        #endregion

        /// <summary>
        /// 将AccessToken替换到URL地址参数中
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        private static string SetToken(this string url)
        {
            AccessTokenDal tokenDal = new AccessTokenDal();
            return url.Replace("=ACCESS_TOKEN", "=" + tokenDal.GetEntToken() + "&t=" + DateTime.Now.Ticks.ToString());
        }
    }
}
